package com.example.androidhive;

import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;


public class MainScreenActivity extends Activity{
	private static final int CAMERA_REQUEST = 1888; 
	
	private ImageView imageView;
	Context aa;
	  ListView listView ;
	Button btnViewProducts;
	Button btnNewProduct,mojekonto_;
	 private class StableArrayAdapter extends ArrayAdapter<String> {
		
		    HashMap<String, Integer> mIdMap = new HashMap<String, Integer>();

		    public StableArrayAdapter(Context context, int textViewResourceId,
		        List<String> objects) {
		      super(context, textViewResourceId, objects);
		      for (int i = 0; i < objects.size(); ++i) {
		        mIdMap.put(objects.get(i), i);
		      }
		    }

		    @Override
		    public long getItemId(int position) {
		      String item = getItem(position);
		      return mIdMap.get(item);
		    }

		    @Override
		    public boolean hasStableIds() {
		      return true;
		    }

		  }
	 protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
	        if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {  
	            Bitmap photo = (Bitmap) data.getExtras().get("data"); 
	            imageView.setImageBitmap(photo);
	        }  
	    } 
	   
		public void onClickStartServie(View V)
		{
			//start the service from here //MyService is your service class name
		    startService(new Intent(this, Serw.class));
			
		}

	//	public Scanner scan;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main_screen);
		 this.imageView = (ImageView)this.findViewById(R.id.ImageView02);
	        Button photoButton = (Button) this.findViewById(R.id.Button02);
	        photoButton.setOnClickListener(new View.OnClickListener() {

	            @Override
	            public void onClick(View v) {
	                Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
	                startActivityForResult(cameraIntent, CAMERA_REQUEST); 
	                
	            }
	        });
        Button btn=(Button)findViewById(R.id.Button01);
        final ImageView imgVi=(ImageView)findViewById(R.id.ImageView01);
         
        btn.setOnClickListener(new OnClickListener()
        {
                public void onClick(View v) 
                 {    
                    Connecetion1 con=new Connecetion1();
                    con.setNetwork();
                    imgVi.setImageBitmap(Data.StoreImg);
                                       
                 }
         });
        /*listView = (ListView) findViewById(R.id.listview);
        String[] values = new String[] { "Android List View", 
                                         "Adapter implementation",
                                         "Simple List View In Android",
                                         "Create List View Android", 
                                         "Android Example", 
                                         "List View Source Code", 
                                         "List View Array Adapter", 
                                         "Android Example List View" 
                                        };
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
          android.R.layout.simple_list_item_1, android.R.id.text1, values);
        listView.setAdapter(adapter); 
        listView.setOnItemClickListener(new OnItemClickListener() {

              @Override
              public void onItemClick(AdapterView<?> parent, View view,
                 int position, long id) {
                
               int itemPosition     = position;
               
               String  itemValue    = (String) listView.getItemAtPosition(position);
                   
                Toast.makeText(getApplicationContext(),
                  "Position :"+itemPosition+"  ListItem : " +itemValue , Toast.LENGTH_LONG)
                  .show();
             
              }

         });*/ 
		// Buttons
		btnViewProducts = (Button) findViewById(R.id.btnViewProducts);
		btnNewProduct = (Button) findViewById(R.id.btnCreateProduct);
		mojekonto_ = (Button) findViewById(R.id.mojekonto);
		//logowanie sie
		mojekonto_.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View view) {
				// Launching All products Activity
			 
				Intent i = new Intent(getApplicationContext(), Logowanie.class);
				startActivity(i);
				/*Intent i = new Intent(getApplicationContext(), Polozenie.class);
				startActivity(i);*/
				/*Uri otherPath = Uri.parse("android.resource://com.example.androidhive/raw/das.mp3");
				AndroidBuildingMusicPlayerActivity aa=new AndroidBuildingMusicPlayerActivity();
				Environment.getExternalStorageDirectory();*/
			//	  Resources res = getResources();
	          //      scan = new Scanner(res.openRawResource(R.raw.das));

	             //   String uri = "android.resource://" + getPackageName() + "/"+R.raw.input;

	            //    System.out.println("FIle Path is" + uri);
			/*	  File baseDir = Environment.getExternalStorageDirectory(); FileDescriptor fd = null;
			        String audioPath = baseDir.getAbsolutePath() +  "das.mp3";
			        FileInputStream fis;
					try {
						fis = new FileInputStream(audioPath);  fd = fis.getFD();
					} catch (FileNotFoundException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}*/
			      
				/* Toast.makeText(getApplicationContext(),
		                  "Position :" , Toast.LENGTH_LONG)
		                  .show();*/
		
				// AndroidBuildingMusicPlayerActivity o2=new AndroidBuildingMusicPlayerActivity(	aa);
			//	  mp.setDataSource("android.resource://" + vv.getPackageName() + "/" + R.raw.das);
			//	 
				
			}
		});
		// view products click event
		btnViewProducts.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View view) {
				// Launching All products Activity
				Intent i = new Intent(getApplicationContext(), AllProductsActivity.class);
				startActivity(i);
				
			}
		});
		
		// view products click event
		btnNewProduct.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View view) {
				// Launching create new product activity
				Intent i = new Intent(getApplicationContext(), NewProductActivity.class);
				startActivity(i);
				
			}
		});
	}
}
